//
//  NumberOf1InBinary.m
//  GLCodingInterview
//
//  Created by colyn on 2019/8/22.
//  Copyright © 2019 colyn. All rights reserved.
//

#import "NumberOf1InBinary.h"

@implementation NumberOf1InBinary

+ (int)numberOf1_1:(int)n {
    int a = n;
    int count = 0;
    while (a) {
        count++;
        a = a&(a-1);
    }
    return count;
}

+ (int)numberOf1_2:(int)n {
    int a = n;
    int count = 0;
    while (a) {
        if (a&1) {
            count++;
        }
        a=a>>1;
    }
    return count;
}

@end
